/*
 * Rating.java
 *
 * This program demonstrates the use of for loop to rate an article.
 *
 */

package com.javacore.day3.article;

import java.util.Scanner;

/**
 * 
 * @author
 */

public class Rating {

	/** Creates a new instance of Rating */
	public Rating() {
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String[] args) {
		int choice = 0;
		boolean ischoice = false;
		int poorCount = 0, fairCount = 0, goodCount = 0, excellentCount = 0;

		Scanner input = new Scanner(System.in);

		System.out.println("Tell us what do you think about the content of"
				+ " the article \"Basics of Java\".");
		System.out.println("1. Poor");
		System.out.println("2. Fair");
		System.out.println("3. Good");
		System.out.println("4. Excellent");
		System.out.println("5. Exit");

		System.out.println("\nEnter your choice:");
		try {
			String strchoice = input.nextLine();
			choice = Integer.parseInt(strchoice);
			ischoice = true;
		} catch (Exception ex) {
			System.out.println("Please enter 1-5!");
			ischoice = false;
		}

		// Iterate the loop until user enters 5
		for (; choice != 5;) {
			if (ischoice == false) {
				break;
			}
			/*
			 * Increment the respective counters depending on the rating entered
			 * by the user
			 */
			switch (choice) {

			case 1:
				poorCount++;
				break;

			case 2:
				fairCount++;
				break;

			case 3:
				goodCount++;
				break;

			case 4:
				excellentCount++;
				break;

			default:
				System.out.println("Invalid input!");
				break;
			}
			try {
				System.out.println("\nEnter your choice:");
				choice = input.nextInt();
			} catch (Exception ex) {

			}
		}
		System.out.println("\nThe article \"Basics of Java\" has received "
				+ "the following ratings:");
		System.out.println("Poor: " + poorCount);
		System.out.println("Fair: " + fairCount);
		System.out.println("Good: " + goodCount);
		System.out.println("Excellent: " + excellentCount);
	}
}
